package organization

import (
	"context"
	pb "git.mycaigou.com/gfyx/micro-gfyx-user-service/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service"
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/service/organization"
)

type Organization struct {
	OrganizationService organization.OrganizationServiceIface
}

//func (s *Organization) GetOrganizationInfo(ctx context.Context, request *pb.GetOrganizationInfoRequest) (*pb.GetOrganizationInfoResponse, error) {
//	panic("implement me")
//}

func NewOrganization(organizationService organization.OrganizationServiceIface) pb.OrganizationServiceServer {
	return &Organization{
		OrganizationService: organizationService,
	}
}

func (s *Organization) SyncAllOrganization(ctx context.Context, request *pb.SyncOrganizationRequest) (*pb.SyncOrganizationResponse, error) {
	/*var response = &pb.SyncOrganizationResponse{}
	response.SyncFlag = false
	if request.TenantCode == "" {
		return nil, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "租户code不能为空")
	}
	//if request.Page < 0 {
	//	return nil, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "页码必须大于等于0")
	//}
	//if request.Pagesize > 10 || request.Pagesize < 1 {
	//	return nil, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "分页size必须大于等于1小于等于10")
	//}

	flag, err := s.OrganizationService.SyncAllOrganization(ctx, request.TenantCode, 0, 10000)
	if err != nil {
		stark.Logger.Error(ctx, err)
		return response, ykerrcode.TogRPCError(errcode.COMMON_ERROR, err.Error())
	}
	if flag != false {
		stark.Logger.Error(ctx, "组织同步失败，租户code："+request.TenantCode)
		return response, ykerrcode.TogRPCError(errcode.COMMON_ERROR, "组织同步失败，租户code："+request.TenantCode)
	}

	response.SyncFlag = true
	return response, nil*/
	return &pb.SyncOrganizationResponse{}, nil
}

//
//func (s *Organization) IncrementSyncOrganization(ctx context.Context, request *pb.IncrementSyncOrganizationRequest) (*pb.IncrementSyncOrganizationResponse, error) {
//	var response = &pb.IncrementSyncOrganizationResponse{}
//	response.SyncFlag = false
//	if request.TenantCode == "" {
//		return nil, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "租户code不能为空")
//	}
//	fmt.Println(request.Operation)
//	if request.Operation != "I" && request.Operation != "U" && request.Operation != "D" {
//		fmt.Println("aaa")
//		return response, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "操作类型错误")
//	}
//	if len(request.OrganizationList) == 0 {
//		fmt.Println("bbb")
//		return response, ykerrcode.TogRPCError(errcode.COMMON_PARAMS_ERROR, "用户列表不能为空")
//	}
//	// todo 放开
//	//userList := []modeling_platfrom_remote.OrganizationInfo{}
//	//for _, info := range request.OrganizationList {
//	//	userInfo := modeling_platfrom_remote.OrganizationInfo{}
//	//	userInfo.OrganizationId = info.OrganizationId
//	//	userInfo.OrganizationCode = info.OrganizationCode
//	//	userInfo.OrganizationName = info.OrganizationName
//	//	userInfo.MobilePhone = info.MobilePhone
//	//	userInfo.IsDisable = info.IsDisable
//	//	userList = append(userList, userInfo)
//	//}
//	//flag, err := s.OrganizationInfoService.IncrSyncOrganization(ctx, request.TenantCode, request.Operation, userList)
//	//if err != nil {
//	//	stark.Logger.Error(ctx, err)
//	//	return response, ykerrcode.TogRPCError(errcode.COMMON_ERROR, err.Error())
//	//}
//	//if flag != false {
//	//	stark.Logger.Error(ctx, "用户同步失败，租户code："+request.TenantCode)
//	//	return response, ykerrcode.TogRPCError(errcode.COMMON_ERROR, "用户同步失败，租户code："+request.TenantCode)
//	//}
//
//	response.SyncFlag = true
//	return response, nil
//}
